<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.infomanage.po.*" %>
<%@page import="com.infomanage.vo.*" %>
<%@page import="com.infomanage.service.plan.*"%>
<%  response.addDateHeader("Expires", 0);response.setHeader("Pragma","no-cache"); response.setHeader("Cache-Control","no-cache");%>
<%
    request.setCharacterEncoding("UTF-8");
	String deviceId = request.getParameter("planId");
    if(deviceId == null) deviceId = "";
    
    DevicerepairPlanItem planItem = DeviceRepairPlanService.loadDeviceRepairPlan(request, response, out);
    int personId = -1;
    int owndeptId = -1;
    int usedeptId = -1;
    String personname = "";
    String owndeptName = "";
    String usedeptName = "";
    String description= "";
    String lastRepairdate = "";
    String planRepairdate = "";
    String deviceType= "";
    String deviceName = "";
    if(planItem != null) {
    	DevicerepairPlan plan = planItem.getBean();
		Department owndept = planItem.getOwnDept();
		Department usedept = planItem.getUseDept();
		Person person = planItem.getPerson();
		personId = plan.getPersonId();
		owndeptId = plan.getOwndeptId();
		usedeptId = plan.getUsedeptId();
	    personname = person.getName();
	    owndeptName = owndept.getPath();
	    usedeptName = usedept.getPath();
	    description = plan.getDesciption();
	    deviceName = plan.getDeviceName();
	    lastRepairdate = plan.getLastRepairdate();
	    planRepairdate = plan.getPlanRepairdate();
	    deviceType = plan.getType();
    } 
%>
<html>
<head>
	<title>设备维修计划</title>
	<link href="../../css/table.css" rel="stylesheet" type="text/css">
	<link href="../../css/calendar.css" rel="stylesheet" type="text/css">
	<link href="../../css/webTree.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="../../js/calendar.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript">
	function clickBody() {
		var srcObj = event.srcElement;
		var treeFrame = document.getElementById("treeFrame");
		if(srcObj.treeSelect == "true"){
			
		}else {
			treeFrame.style.display = "none";
		}
	}
	
	function selectNode(id, title){
		currTreeInputObj.value = title;
		currTreeInputObj.nextSibling.value = id;
		var treeFrame = document.getElementById("treeFrame");
		treeFrame.style.display = "none";
	}
	
	 function init() {
		   if("" != "<%=deviceId%>") { // 修改
		   	 form1.personId.value = "<%=personId%>";	
		   	 form1.owndeptId.value = "<%=owndeptId%>";	
		   	 form1.usedeptId.value = "<%=usedeptId%>";	
		   	 form1.personname.value = "<%=personname%>";	
		   	 form1.owndeptName.value = "<%=owndeptName%>";	
		   	 form1.usedeptName.value = "<%=usedeptName%>";	
		   	 form1.description.value = "<%=description%>";	
		   	 form1.deviceName.value = "<%=deviceName%>";	
		   	 form1.lastRepairdate.value = "<%=lastRepairdate%>";	
		   	 form1.planRepairdate.value = "<%=planRepairdate%>";	
		   	 form1.deviceType.value = "<%=deviceType%>";	
		   }
	   }
	   // 提交
	   function doSubmit(){
	   		if(validate()){
	   			return;
	   		}
		 	if("" == "<%=deviceId%>") {
		 		form1.actionType.value = "add";
			}else {
		 		form1.actionType.value = "modify";
			}
		 	form1.submit();
	   }

	   function validate(){
	   		if(form1.deviceName.value == ""){
	   			alert("设备名称不能为空！");
	   			return true;
	   		}
	   		if(form1.owndeptId.value == ""){
	   			alert("所属单位不能为空！");
	   			return true;
	   		}
	   		if(form1.usedeptId.value == ""){
	   			alert("使用单位不能为空！");
	   			return true;
	   		}
	   		if(form1.personId.value == ""){
	   			alert("负责人不能为空！");
	   			return true;
	   		}
	   		
	   		if(form1.deviceName.value.length > 100){
   				alert("设备名称不能超过100个字！");
   				return true;
	   	    }
	   		if(form1.deviceType.value.length > 50){
   				alert("备注不能超过50个字！");
   				return true;
	   	    }
	   		if(form1.description.value.length > 1000){
   				alert("备注不能超过5000个字！");
   				return true;
	   	    }
	   		return false;
	   }
	   
	   function showError(error){
		   alert(error);
	   }

	   function showInfo(info){
		   alert(info);
		   window.returnValue = "ok";
		   window.close();
	   }
	</script>
</head>
<body  rightmargin="0" bottommargin="0" leftmargin="0" topmargin="0" onclick="clickBody();" onload="init();">
	<form name="form1" action="deviceRepair_action.jsp" method="post" target="actionFrame">
	<input type="hidden" name="planId" value="<%=deviceId%>">
	<input type="hidden" name="actionType">
	<table class="dialogTable" cellpadding="0" cellspacing="0">
		<!-- 表头-->
		<tr class="dialogTableHeader">
			<td>装备修理计划</td>
		</tr>
		<!-- 表数据-->
		<tr class="dialogTableContent">
			<td>
				<!-- 数据项 -->
				<table class="dataTable">
					<col width="30%">
					<col width="70%">
					<tr>
						<td class="field">
							设备名称
						</td>
						<td>
							<input name="deviceName" value="" style="width: 100%;">
						</td>
					</tr>
					<tr>
						<td class="field">
							所属单位
						</td>
						<td>
							<span class="treeSpan" onclick="showTree(this, '../common/deptTree.jsp');" treeSelect="true">
								<input name="owndeptName" value="" style="width: 338px;" readonly="readonly" treeSelect="true"><input name="owndeptId" value="" type="hidden">
							</span>
						</td>
					</tr>
					<tr>
						<td class="field">
							使用单位
						</td>
						<td>
							<span class="treeSpan" onclick="showTree(this, '../common/deptTree.jsp');" treeSelect="true">
								<input name="usedeptName" value="" style="width: 338px;" readonly="readonly" treeSelect="true"><input name="usedeptId" value="" type="hidden">
							</span>
						</td>
					</tr>
					<tr>
						<td  class="field">
							负责人
						</td>
						<td>
							<span class="treeSpan" onclick="showTree(this, '../common/personTree.jsp');" treeSelect="true">
								<input name="personname" value="" style="width: 338px;" readonly="readonly" 
								treeSelect="true"><input name="personId" value="" type="hidden">
							</span>
						</td>
					</tr>
					<tr>
						<td class="field">
							型号
						</td>
						<td>
							<input name="deviceType" value="" style="width: 100%;">
						</td>
					</tr>
					<tr>
						<td class="field">
							上次维修时间
						</td>
						<td>
							<input name="lastRepairdate" type="text" style="width: 230px;cursor: hand;" id="time1" onClick="return showCalendar(this.id, 'y-mm-dd');" readonly="readonly"><img 
									src="../../img/tip_calender.gif" style="cursor: hand;" width="16" height="16" onClick="return showCalendar('time1', 'y-mm-dd');">
						</td>
					</tr>
					<tr>
						<td class="field">
							计划维修时间
						</td>
						<td>
							<input name="planRepairdate" type="text" style="width: 230px;cursor: hand;" id="time2" onClick="return showCalendar(this.id, 'y-mm-dd');" readonly="readonly"><img 
									src="../../img/tip_calender.gif" style="cursor: hand;" width="16" height="16" onClick="return showCalendar('time2', 'y-mm-dd');">
						</td>
					</tr>
					<tr style="height: 100px">
						<td class="field">
							备注
						</td>
						<td valign="top">
							<textarea name="description" style="width: 100%;height: 100%"></textarea>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2" class="tableBtn">
				<span onclick="doSubmit();">确定</span>
				<span onclick="window.close();">取消</span>
			</td>
		</tr>
		<tr valign="top">
			<td colspan="2">
				&nbsp;
			</td>
		</tr>
	</table>
	</form>
	<iframe src="#" frameborder="0" id="treeFrame" name="frame" style="display: none;position: absolute;"></iframe>
	<iframe src="#" name="actionFrame" style="display: none;"></iframe>
</body>
</html>